package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.onPackageExpiresBean;
import com.ymatou.iapi.godmch.service.createmchCall;
import com.ymatou.iapi.godmch.service.onPackageExpiresCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
/**
*订购套餐过期MQ回调
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_onPackageExpires{
	private static onPackageExpiresBean bean;
	private static onPackageExpiresCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("订购套餐过期MQ回调");
	}

	@Before
	public void caseUp() {
		bean=new onPackageExpiresBean();
		call=new onPackageExpiresCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	/**
	 * 	自营商品 mch_info   channels=0 ，不是自营商品，channels就不更改
	 */
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_onPackageExpires_001() {
		Logger.start(true,"订购套餐过期MQ回调-自营商品");
		try {

			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int mchId_agentId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			createmchCall createmchCall=GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			createmchBean=GodmchManageCallService.InitcreatemchBeanForAgent(createmchBean.getMchId(), mchId_agentId).get(0);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			bean.setUserId(mchId_agentId);
			bean.setFuncType(6);
			call.setData(bean);
			call.callService();			
			mch_infoWapper mchInfoWapper = new mch_infoWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", bean.getUserId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
	        Logger.verifyEquals(0, mchInfo.getChannels(), "验证返回成功Channels");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_onPackageExpires_002() {
		Logger.start(true,"订购套餐过期MQ回调-不是自营商品");
		try {

			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int mchId_agentId = DGUserCallService.UserCreateCall(usercreateBean);
			
			createmchBean createmchBean=GodmchManageCallService.InitcreatemchBeanForChannel();
			createmchCall createmchCall=GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			createmchBean=GodmchManageCallService.InitcreatemchBeanForAgent(createmchBean.getMchId(), mchId_agentId).get(0);
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			
			bean.setUserId(mchId_agentId);
			bean.setFuncType(5);
			call.setData(bean);
			call.callService();			
			mch_infoWapper mchInfoWapper = new mch_infoWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", bean.getUserId());
			mch_info mchInfo = mchInfoWapper.selectby(map).get(0);
	        Logger.verifyEquals(1, mchInfo.getChannels(), "验证返回成功Channels");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}